package com.its.common.disruptor.use;

import com.its.common.disruptor.consumer.BaseMessageConsumer;
import com.its.common.disruptor.dto.TranslatorData;
import com.its.common.disruptor.dto.TranslatorDataWapper;
import lombok.extern.slf4j.Slf4j;

import java.util.Arrays;
import java.util.Locale;

/**
 * @Author xiaxp
 * @Date 2021-11-25 16:34
 * @Description
 */
@Slf4j
public class MessageConsumerImpl extends BaseMessageConsumer {

	public MessageConsumerImpl(String consumerId) {
		super(consumerId);
	}

	@Override
	public void handleData(TranslatorDataWapper translatorDataWapper) {
		TranslatorData request = translatorDataWapper.getData();
		//业务处理逻辑: 数据库持久化操作 IO读写 ---> 交给一个线程池 去异步的调用执行
//		log.info(consumerId + ", " + Thread.currentThread().getId()
//				+"--- 消费者端: id= " + request.getId());

		Arrays.toString(request.getMessage());
	}

	public static void main(String[] args) {
		System.out.println(format("Disruptor-pool-%d", 11));
	}

	private static String format(String format, Object... args) {
		return String.format(Locale.ROOT, format, args);
	}

}
